var app = getApp(),
    util = require("../../utils/util.js"),
    imgArray = [],
    imgArray1 = [],
    lbimgArray = [],
    lbimgArray1 = [],
    imglogo = "";
Page({
    data: {
        index: 0,
        zsnum: 0,
        lbimages1: [],
        images1: [],
        logo: []
    },
    onLoad: function(e) {
        imgArray = [], imgArray1 = [], lbimgArray = [], lbimgArray1 = [];
        var a = wx.getStorageSync("System").is_tel,
            t = (wx.getStorageSync("UserData").id, wx.getStorageSync("users")),
            o = this;
        console.log(t), console.log(getApp().imglink, getApp().getuniacid);
        var n = wx.getStorageSync("url");
        app.util.request({
            url: "entry/wxapp/StoreType",
            cachetime: "0",
            success: function(e) {
                console.log(e);
                var l = e.data,
                    i = [];
                l.map(function(e) {
                    var a = {};
                    a = e.type_name, i.push(a)
                }), console.log(i), o.setData({
                    nav: i,
                    store: l,
                    link: n,
                    is_tel: a,
                    user_info: t
                })
            }
        }), app.util.request({
            url: "entry/wxapp/YellowSet",
            cachetime: "0",
            success: function(e) {
                console.log(e);
                var a = [];
                for (var t in e.data) {
                    var n = e.data;
                    0 == e.data[t].money ? e.data[t].money1 = "免费" : e.data[t].money1 = e.data[t].money + "元", e.data[t].text = e.data[t].days + "天 " + e.data[t].money1
                }
                e.data.map(function(e) {
                    var t = {};
                    t.value = e.text, t.name = e.id, a.push(t)
                }), console.log(a), a[0].checked = !0, o.setData({
                    items: a,
                    yellow_set: n,
                    rz_type: a[0].name
                })
            }
        });
        var l = wx.getStorageSync("url2");
        console.log(n), this.setData({
            url: l,
            link: n
        })
    },
    getPhoneNumber: function(e) {
        var a = this,
            t = wx.getStorageSync("key"),
            o = e.detail.iv,
            n = e.detail.encryptedData;
        console.log(t), console.log(o), console.log(n), app.util.request({
            url: "entry/wxapp/jiemi",
            cachetime: "0",
            data: {
                sessionKey: t,
                iv: o,
                data: n
            },
            success: function(e) {
                console.log(e), a.setData({
                    num: e.data.phoneNumber
                })
            }
        })
    },
    bindPickerChange: function(e) {
        console.log("picker发送选择改变，携带值为", e.detail.value), this.setData({
            index: e.detail.value
        })
    },
    radioChange: function(e) {
        console.log("radio发生change事件，携带value值为：", e.detail.value), this.setData({
            rz_type: e.detail.value
        })
    },
    choose: function(e) {
        var a = this,
            t = a.data.url,
            o = wx.getStorageSync("uniacid");
        console.log(t), console.log(o), wx.chooseImage({
            count: 1,
            sizeType: ["original", "compressed"],
            sourceType: ["album", "camera"],
            success: function(e) {
                console.log(e);
                var n = e.tempFilePaths[0];
                wx.uploadFile({
                    url: t + "app/index.php?i=" + o + "&c=entry&a=wxapp&do=Upload&m=zh_tcwq",
                    filePath: n,
                    name: "upfile",
                    formData: {},
                    success: function(e) {
                        console.log(e);
                        var t = a.data.logo;
                        t[0] = e.data, a.setData({
                            logo: t
                        })
                    },
                    fail: function(e) {
                        console.log(e)
                    }
                })
            }
        })
    },
    lbdelete1: function(e) {
        var a = this,
            t = e.currentTarget.dataset.index,
            o = a.data.logo;
        o.splice(t, 1), console.log(o), a.setData({
            logo: o
        })
    },
    gongg: function(e) {
        console.log(e.detail.value);
        var a = parseInt(e.detail.value.length);
        this.setData({
            zsnum: a
        })
    },
    add: function(e) {
        var a = this;
        wx.chooseLocation({
            type: "wgs84",
            success: function(e) {
                console.log(e);
                e.latitude, e.longitude, e.speed, e.accuracy;
                a.setData({
                    address: e.address,
                    start_lat: e.latitude,
                    start_lng: e.longitude
                })
            }
        })
    },
    formSubmit: function(e) {
        console.log(e);
        var a = this;
        if (1 == wx.getStorageSync("city_type")) t = wx.getStorageSync("city");
        else var t = wx.getStorageSync("city1");
        var o = e.detail.value.name,
            n = e.detail.value.tel,
            l = e.detail.value.details,
            i = e.detail.value.address,
            s = "",
            c = a.data.logo,
            r = a.data.yellow_set,
            u = (a.data.items, a.data.start_lat + "," + a.data.start_lng);
        console.log(u);
        var g = a.data.store,
            d = a.data.nav[a.data.index];
        if (2 == a.data.is_tel) p = 1;
        else var p = a.data.num;
        for (var m in g) if (g[m].type_name == d) var y = g[m].id;
        var f = a.data.rz_type;
        for (var v in r) if (r[v].id == f) {
            console.log(r[v].money);
            var w = Number(r[v].money)
        }
        if (console.log(r), console.log(a.data.rz_type), console.log(c[0]), "" == o ? s = "公司名称不能为空" : "" == n ? s = "公司电话不能为空" : "" == l ? s = "公司简介不能为空" : null == i || "" == i ? s = "请正确填写公司地址" : 0 == c.length ? s = "请上传公司logo" : null == p && (s = "还没进行手机号验证"), "" != s) wx.showModal({
            title: "提示",
            content: s,
            showCancel: !0,
            cancelText: "取消",
            confirmText: "确定",
            success: function(e) {},
            fail: function(e) {},
            complete: function(e) {}
        });
        else {
            c = c[0];
            var h = wx.getStorageSync("users").id,
                x = wx.getStorageSync("openid");
            w > 0 ? app.util.request({
                url: "entry/wxapp/Pay",
                cachetime: "0",
                data: {
                    openid: x,
                    money: w
                },
                success: function(e) {
                    console.log(e), wx.requestPayment({
                        timeStamp: e.data.timeStamp,
                        nonceStr: e.data.nonceStr,
                        package: e.data.package,
                        signType: e.data.signType,
                        paySign: e.data.paySign,
                        success: function(e) {
                            console.log("这里是支付成功"), console.log(e), app.util.request({
                                url: "entry/wxapp/YellowPage",
                                cachetime: "0",
                                data: {
                                    user_id: h,
                                    logo: c,
                                    company_name: o,
                                    company_address: i,
                                    type_id: y,
                                    link_tel: n,
                                    rz_type: f,
                                    coordinates: u,
                                    content: l,
                                    imgs: "",
                                    tel2: p,
                                    cityname: t
                                },
                                success: function(e) {
                                    console.log(e), app.util.request({
                                        url: "entry/wxapp/SaveHyPayLog",
                                        cachetime: "0",
                                        data: {
                                            hy_id: e.data,
                                            money: w
                                        },
                                        success: function(e) {
                                            console.log(e)
                                        }
                                    }), wx.showModal({
                                        title: "提示",
                                        content: "提交成功等待审核"
                                    }), setTimeout(function() {
                                        wx.navigateBack({
                                            delta: 1
                                        })
                                    }, 2e3)
                                }
                            })
                        },
                        fail: function(e) {
                            console.log("这里是支付失败"), console.log(e), wx.showToast({
                                title: "支付失败",
                                duration: 1e3
                            })
                        }
                    })
                }
            }) : app.util.request({
                url: "entry/wxapp/YellowPage",
                cachetime: "0",
                data: {
                    user_id: h,
                    logo: c,
                    company_name: o,
                    company_address: i,
                    type_id: y,
                    link_tel: n,
                    rz_type: f,
                    coordinates: u,
                    content: l,
                    imgs: "",
                    tel2: p,
                    cityname: t
                },
                success: function(e) {
                    console.log(e), wx.showToast({
                        title: "入驻成功",
                        icon: "",
                        image: "",
                        duration: 2e3,
                        mask: !0,
                        success: function(e) {},
                        fail: function(e) {},
                        complete: function(e) {}
                    }), setTimeout(function() {
                        wx.navigateBack({
                            delta: 1
                        })
                    }, 2e3)
                }
            })
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
});